import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
import Login from '@/views/login'
import Layout from '@/views/layout'
import Dashboard from '@/views/dashboard'
import Institution from '@/views/institution'
import Institutionalscope from '@/views/Institutionalscope'
import Freightmanagement from '@/views/freightmanagement'
import Chelmanagement from '@/views/chelmanagement'
import Vehiclelist from '@/views/vehiclelist'
import Returnregistration from '@/views/returnregistration'
import Couriermanagement from '@/views/couriermanagement'
import Drivermanagement from '@/views/drivermanagement'
import Workforcemanagement from '@/views/workforcemanagement'
import Ordermanagement from '@/views/ordermanagement'
import Waybillmanagement from '@/views/waybillmanagement'
import Transportationtaskmanagement from '@/views/transportationtaskmanagement'
import Linemanagement from '@/views/linemanagement'
import Pickupoperation from '@/views/pickupoperation'
import Dispatchjob from '@/views/dispatchjob'
Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/',
    component: Layout,
    // 重定向
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: Dashboard
      },
      {
        path: 'institution',
        component: Institution
      },
      {
        path: 'Institutionalscope',
        component: Institutionalscope
      },
      {
        path: 'freightmanagement',
        component: Freightmanagement
      },
      {
        path: 'chelmanagement',
        component: Chelmanagement
      },
      {
        path: 'vehiclelist',
        component: Vehiclelist
      },
      // 车辆列表查看详情
      {
        path: 'vehiclelist/info/:id', // 二级默认路由
        component: () => import('@/views/vehiclelist/info') // 按需加载
      },
      {
        path: 'returnregistration',
        component: Returnregistration

      },
      {
        path: 'couriermanagement',
        component: Couriermanagement
      },
      {
        path: 'drivermanagement',
        component: Drivermanagement
      },
      {
        path: 'workforcemanagement',
        component: Workforcemanagement
      },
      {
        path: 'workforcemanagement/workArrangeInfo/', // 二级默认路由
        component: () => import('@/views/workforcemanagement/workArrangeInfo') // 按需加载
      },
      {
        path: 'ordermanagement',
        component: Ordermanagement
      },
      {
        path: 'waybillmanagement',
        component: Waybillmanagement
      },
      {
        path: 'transportationtaskmanagement',
        component: Transportationtaskmanagement
      },
      {
        path: 'linemanagement',
        component: Linemanagement
      },
      {
        path: 'pickupoperation',
        component: Pickupoperation
      },
      {
        path: 'dispatchjob',
        component: Dispatchjob
      },
      {
        path: 'returnregistration/info/:id', // 二级默认路由
        component: () => import('@/views/returnregistration/info') // 按需加载
      },
      // 快递员管理详情
      {
        path: 'couriermanagement/distribution/:id', // 二级默认路由
        component: () => import('@/views/couriermanagement/distribution') // 按需加载
      },
      // 司机管理详情
      {
        path: 'drivermanagement/driverInfo/:id', // 二级默认路由
        component: () => import('@/views/drivermanagement/driverInfo') // 按需加载
      },
      // 查看车辆查看车辆详情
      {
        path: 'drivermanagement/driverCart/:id', // 二级默认路由
        component: () => import('@/views/drivermanagement/driverCart') // 按需加载
      },
      // 业务管理订单详情
      {
        path: 'ordermanagement/orderInfo/:id', // 二级默认路由
        component: () => import('@/views/ordermanagement/orderInfo') // 按需加载
      },
      // 运单管理查看详情
      {
        path: 'waybillmanagement/waybillInfo/:id', // 二级默认路由
        component: () => import('@/views/waybillmanagement/waybillInfo') // 按需加载
      },
      // 运单任务管理详情
      {
        path: 'transportationtaskmanagement/transportationInfo/:id', // 二级默认路由
        component: () => import('@/views/transportationtaskmanagement/transportationInfo') // 按需加载
      }
    ]
  }
]

const router = new VueRouter({
  routes
})
// 路由前置导航守卫
router.beforeEach((to, from, next) => {
  const token = store.state.user.token
  if (to.path !== '/login' && !token) return next('/login')
  next()
})
export default router
